package git.bankview.wl.common;

import java.util.*;
import java.text.*;
import java.sql.*;

import laya.semi.process.*;

import git.bankview.sl.db.*;

import org.apache.log4j.Logger;

public class ActivityUtils
{
	private static Logger log = Logger.getLogger(ActivityUtils.class);
	
	private static long DAY_TIMESLICE = 1000 * 3600 * 24;
	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
	
	public static String getCodePrefix(String oCode)
	{
		int i;
		for (i = oCode.length() - 1; i >= 0; --i)
		{
			if ('0' != oCode.charAt(i))
			{
				break;
			}
		}
		
		return oCode.substring(0, i + 1);
	}
	
	public static long diffDays(java.util.Date oFromDate, java.util.Date oToDate)
	{
		Calendar c = Calendar.getInstance();
		c.setTime(oFromDate);
		c.set(Calendar.HOUR_OF_DAY, 0);
		c.set(Calendar.MINUTE, 0);
		c.set(Calendar.SECOND, 0);
		c.set(Calendar.MILLISECOND, 0);
		long from = c.getTimeInMillis();
		c.setTime(oToDate);
		c.set(Calendar.HOUR_OF_DAY, 0);
		c.set(Calendar.MINUTE, 0);
		c.set(Calendar.SECOND, 0);
		c.set(Calendar.MILLISECOND, 0);
		long to = c.getTimeInMillis();

		return (to - from) / DAY_TIMESLICE;
	}
	
	public static long diffMonths(java.util.Date oFromDate, java.util.Date oToDate)
	{
		Calendar cal = Calendar.getInstance();
		cal.setTime(oToDate);
		int y = cal.get(Calendar.YEAR);
		int m = cal.get(Calendar.MONTH);
		cal.setTime(oFromDate);
		y -= cal.get(Calendar.YEAR);
		m -= cal.get(Calendar.MONTH);
		return y * 12 + m;
	}
}

